package com.common.help.test02;

import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;

public class SocketClient2 {

	public static void main(String[] args) throws Exception {
		
		int port = 12345;
		String host = "127.0.0.1";
		Socket socket = new Socket(host,port);
		String message = "hello server";
		OutputStream os = socket.getOutputStream();
		os.write(message.getBytes());
		socket.shutdownOutput();
		
		InputStream is = socket.getInputStream();
		byte[] b = new byte[2048];
		int len=0;
		StringBuffer sb = new StringBuffer();
		while((len=is.read(b))!=-1){
			sb.append(new String(b,0,len,"UTF-8"));
		}
		System.out.println("from server "+sb);
		is.close();
		os.close();
		socket.close();
	}
}
